#include "btform.h"
#include "ui_btform.h"

BtForm::BtForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::BtForm)
{
    ui->setupUi(this);
}

BtForm::~BtForm()
{
    delete ui;
}

int BtForm::getpageId() const
{
    return this->pageId;
}

QMovie *BtForm::getMov() const
{
    return this->mov;
}

QLabel *BtForm::getEffectLabel() const
{
    return ui->btEffect;
}

void BtForm::cleanBackground()
{
   ui->BtStyle->setStyleSheet("#BtStyle{background-color:rgb(166, 197, 255);}#BtStyle:hover{background-color:#4380d9;}");
}

void BtForm::setBtStyle(const QString &icon, const QString &text,int pageId)
{
    //设置图片
    QPixmap *pix=new QPixmap(icon);
    pix->scaled(ui->btLogo->size(),Qt::KeepAspectRatio);
    ui->btLogo->setScaledContents((true));
    ui->btLogo->setPixmap(*pix);

    //设置文本
    ui->btText->setText(text);

    //设置pageId
    this->pageId=pageId;
}

void BtForm::mousePressEvent(QMouseEvent *event)
{
    (void)event;
    //设置点击背景颜色
    ui->BtStyle->setStyleSheet("#BtStyle{background-color:#4482d9;}");
    mov=new QMovie(":/res/clickMove.gif");
    QSize size(ui->btEffect->width(),ui->btEffect->height());
    mov->setScaledSize(size);
    mov->start();
    ui->btEffect->setMovie(mov);

    emit BtClick(this->pageId);
//    QMovie *mov=new QMovie(":/res/clickMove.gif");
//    mov->start();
//    ui->btEffect->setMovie(mov);
}
